<template>
  <div id="app-page">
    <el-affix :offset="0" z-index="200">
      <TopNav></TopNav>
    </el-affix>
    <router-view />
  </div>

  <back-top />
</template>

<script lang="ts" setup>
import { onMounted } from "vue";
import TopNav from "@/views/top_nav/TopNav.vue";
import BackTop from "@/components/BackTop.vue";
import userApi from "@/api/user";
import store from "@/store/store";
import { setToken } from "./utils/common";

onMounted(() => {
  userApi.autoLogin().then((res) => {
    if (res.data.code === 0) {
      // 将用户信息放在pinia，供任何地方使用
      store().setUserInfo(res.data.data);
      // 每次自动登录刷新token
      setToken(res.data.data.token);
    }
  });
});
</script>

<style lang="scss" scoped>
#app-page {
  margin: 0 auto;
  width: 1400px;
  height: calc(100vh);
}
</style>
